package cn.devzyh.oms.coms.express.service.impl;

import cn.devzyh.oms.coms.api.express.dto.LocationDTO;
import cn.devzyh.oms.coms.api.express.entity.Area;
import cn.devzyh.oms.coms.api.order.entity.OrderHeader;
import cn.devzyh.oms.coms.express.mapper.AreaMapper;
import cn.devzyh.oms.coms.express.service.AreaService;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

@Service
public class AreaServiceImpl extends ServiceImpl<AreaMapper, Area> implements AreaService {

	@Override
	public LocationDTO getReceiveLocation(OrderHeader orderHeader) {
		String areaCode = orderHeader.getReceiveStreet();
		if (StrUtil.isBlank(areaCode)) {
			areaCode = orderHeader.getReceiveDistrict();
		}
		if (StrUtil.isBlank(areaCode)) {
			areaCode = orderHeader.getReceiveCity();
		}
		if (StrUtil.isBlank(areaCode)) {
			areaCode = orderHeader.getReceiveState();
		}

		Area area = getById(areaCode);
		if (area == null) {
			return null;
		}

		LocationDTO dto = new LocationDTO();
		dto.setLatitude(area.getLatitude());
		dto.setLatitude(area.getLongitude());
		return dto;
	}

}